package com.xrkj.miniprogram.server.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xrkj.miniprogram.server.entity.MiniprogramUser;
import com.xrkj.miniprogram.server.entity.RegistrationRequest;
import com.xrkj.miniprogram.server.mapper.MiniprogramUserMapper;
import com.xrkj.miniprogram.server.mapper.RegistrationRequestMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class RegisterConfirmService {
    @Autowired
    RegistrationRequestMapper registrationRequestMapper;
    @Autowired
    MiniprogramUserMapper miniprogramUserMapper;

    @Transactional
    public void registerConfirm(Integer registrationRequestID){
        RegistrationRequest registrationRequest= registrationRequestMapper.selectById(registrationRequestID);
        MiniprogramUser miniprogramUser=new MiniprogramUser();
        miniprogramUser.setWxid(registrationRequest.getWxOpenid())
                .setNickname(registrationRequest.getNickname())
                .setPosition(registrationRequest.getPosition())
                .setGroupName(registrationRequest.getGroupName())
                .setCreatedAt(new Date());

        miniprogramUserMapper.insert(miniprogramUser);


    }

    public List<RegistrationRequest> getAllRegistrationRequest(){
        QueryWrapper<RegistrationRequest> queryWrapper=new QueryWrapper<>();
        List<RegistrationRequest> allRegistrationRequest=registrationRequestMapper.selectList(queryWrapper);
        return allRegistrationRequest;
    }
}
